package com.woniu.his.controller;

import com.woniu.his.service.TaoService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TaoNurseController {
    @Autowired
    private TaoService taoService;

    //这是进入护士界面的请求
    @RequiresRoles("护士部")
    @GetMapping("tao-nurse-page")
    public String taoNursePage() {
        return "tao-nurse-page";
    }

    //这是获取住院申请的请求
    @RequiresRoles("护士部")
    @PostMapping("tao-inHospitalApplyQuery")
    @ResponseBody
    public List<Map<String, Object>> taoInHospitalApplyQuery() {
        return taoService.taoFindAllHospitalApplyStatusFalseInfo();
    }

    //这是查询病人对应的病房号对象
    @PostMapping("tao-queryWardInfo")
    @ResponseBody
    @RequiresRoles("护士部")
    public List<Map<String, Object>> taoQueryWardInfo(int sectionId) {
        List<Map<String, Object>> list = taoService.findWardInfoBySectionId(sectionId);
        return list;
    }

    //这是查询出对应病房号中可以使用的病床对象的请求
    @PostMapping("tao-querySickbedInfo")
    @ResponseBody
    @RequiresRoles("护士部")
    public List<Map<String, Object>> taoQuerySickbedInfo(int wardId) {
        List<Map<String, Object>> list = taoService.findEmptySickbedInfoByWardId(wardId);
        return list;
    }

    //这是住院信息提交的请求
    @PostMapping("tao-hospital-commit")
    @ResponseBody
    @RequiresRoles("护士部")
    public Map<String, String> taoHospitalCommit(@RequestBody Map<String, Object> map) {
        //接收到前端穿过来的数据进行住院表的更新
        String result = taoService.taoUpdateHospitalInfo(map);
        Map<String, String> callInfo = new HashMap<>();
        if (result == null) {
            callInfo.put("message", "操作失败");
        } else {
            callInfo.put("message", "操作成功");
        }
        return callInfo;
    }

    //这是查询出所有要出院的患者的信息
    @PostMapping("tao-query-outHospitalInfo")
    @ResponseBody
    @RequiresRoles("护士部")
    public List<Map<String, Object>> taoQueryOutHospitalInfo() {
        List<Map<String, Object>> list = taoService.taoFindAllOutHospitalApplyInfo();
        return list;
    }

    //这是办理出院的请求
    @PostMapping("tao-outHospital-confirm")
    @ResponseBody
    @RequiresRoles("护士部")
    public Map<String, String> taoOutHospitalConfirm(int hosipitalizationInfoId) {
        String result = taoService.updateHospitalInfoAddOutHospitalStatus(hosipitalizationInfoId);
        Map<String, String> callInfo = new HashMap<>();
        if (result == null) {
            callInfo.put("message", "操作失败");
        } else {
            callInfo.put("message", "操作成功");
        }
        return callInfo;
    }

    //这是查询药品申请的请求
    @PostMapping("tao-drugApply-query")
    @ResponseBody
    @RequiresRoles("护士部")
    public List<Map<String, Object>> taoDrugApplyQuery() {
        List<Map<String, Object>> list = taoService.taoFindAllDrugApplyByMedicalIsHospitalization();
        return list;
    }

    //这是去拿药的请求
    @PostMapping("tao-gotoGetDrug")
    @ResponseBody
    @RequiresRoles("护士部")
    public Map<String, String> taoGotoGetDrug(int drugApplyId) {
        System.out.println("药瓶申请ID" + drugApplyId);
        String result = taoService.updateDrugApplyInfoById(drugApplyId);
        Map<String, String> callInfo = new HashMap<>();
        if (result == null) {
            callInfo.put("message", "操作失败");
        } else {
            callInfo.put("message", "操作成功");
        }
        return callInfo;
    }
}
